package com.f.service;

import com.f.bean.Emp;
import com.f.bean.EmpDept;
import com.f.mapper.EmpMapper;
import com.f.repository.EmpRepository;
import io.searchbox.client.JestClient;
import io.searchbox.core.Search;
import io.searchbox.core.SearchResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;


import java.io.IOException;
import java.util.List;

@Service
public class EmpService {
    @Autowired
    private EmpMapper empMapper;

    @Autowired
    private JestClient jestClient;

    @Autowired
    private EmpRepository empRepository;

    @Cacheable(value = "emp")
    public EmpDept getById(Integer id){
        return empMapper.getById(id);
    }


    public List<Emp> getByName(String empName){


        List<Emp> list = empRepository.findByEmpName(empName);
        if(list.size() > 0){
            return list;
        }


        List<Emp> list1 = empMapper.getByName(empName);
        list1.forEach(emp->empRepository.save(emp));
        return list1;


    }
}
